/**
 * @file uart_test.c
 * @author Rocky
 * @brief 串口测试
 * @version 0.1
 * @date 2024-03-22
 * 
 * @copyright Copyright (c) 2024
 * 
 */

#include "uart_interface.h"

#define PROGRAM_NAME "uart_test"

int main(int argc, char *argv[])
{
    char ch;
    int fd, ret;

    fd = uart_open(fd, "/dev/ttySTM2");
    if (fd == -1)
        errmsg_die("uart_open error\n");

    if (uart_set(fd, 9600, 0, 8, 'N', 1) == -1)
        errmsg_die("uart set failed!\n");

    while (1)
    {
        ret = uart_read(fd, &ch, 1);
        if (ret == -1)
            errmsg_die("uart read failed!\n");
        printf("%c", ch);
    }

    ret = uart_close(fd);
    if (ret == -1)
        errmsg_die("uart_close error\n");

    exit(EXIT_SUCCESS);
}
